package L1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class _048 {
    /**
     *  矩阵A乘以B
     */
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] s1 = reader.readLine().split(" ");
        int Ra = Integer.valueOf(s1[0]);
        int Ca = Integer.valueOf(s1[1]);
        int[][] A = new int[Ra][Ca];
        for (int i=0;i<Ra;i++){
            String[] s = reader.readLine().split(" ");
            for (int j=0;j<Ca;j++){
                A[i][j]=Integer.valueOf(s[j]);
            }
        }
        String[] s2 = reader.readLine().split(" ");
        int Rb = Integer.valueOf(s2[0]);
        int Cb = Integer.valueOf(s2[1]);
        if (Ca!=Rb){
            System.out.println("Error: "+Ca+" != "+Rb);
            return;
        }
        int[][] B = new int[Rb][Cb];
        for (int i=0;i<Rb;i++){
            String[] s = reader.readLine().split(" ");
            for (int j=0;j<Cb;j++){
                B[i][j] = Integer.valueOf(s[j]);
            }
        }
        int[][] result = new int[Ra][Cb];
        for (int i=0;i<Ra;i++){
            for (int k=0;k<Cb;k++){
                int sum=0;
                for (int j =0;j<Ca;j++){
                    sum+=A[i][j]*B[j][k];
                }
                result[i][k] = sum;
            }
        }
        System.out.println(Ra+" "+Cb);
        for (int i=0;i<Ra;i++){
            for (int j=0;j<Cb;j++){
                if (j==Cb-1){
                    System.out.print(result[i][j]);
                }else {
                    System.out.print(result[i][j]+" ");
                }

            }
            System.out.println();
        }
    }
}
